package dao;

import bean.attendance;

import org.apache.ibatis.session.SqlSession;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;


public class attend {
    public static void attendance(String name){
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        SqlSession sqlSession =(SqlSession) context.getBean("sqlSession");
        AttendanceMapper attendanceMapper=sqlSession.getMapper(AttendanceMapper.class);
        attendance attendance=new attendance();
        attendance.setName(name);
        attendance.setStatus("出勤");
        int insert=attendanceMapper.insert(attendance);
        System.out.println("出勤 Affected rows: " + insert);
    }
    public static void absence(String name){
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        SqlSession sqlSession =(SqlSession) context.getBean("sqlSession");
        AttendanceMapper attendanceMapper=sqlSession.getMapper(AttendanceMapper.class);
        attendance attendance=new attendance();
        attendance.setName(name);
        attendance.setStatus("缺勤");
        int insert=attendanceMapper.insert(attendance);
        System.out.println("缺勤 Affected rows: " + insert);
    }
    public static void leave(String name){
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        SqlSession sqlSession =(SqlSession) context.getBean("sqlSession");
        AttendanceMapper attendanceMapper=sqlSession.getMapper(AttendanceMapper.class);
        attendance attendance=new attendance();
        attendance.setName(name);
        attendance.setStatus("请假");
        int insert=attendanceMapper.insert(attendance);
        System.out.println("请假 Affected rows: " + insert);
    }
    public static void show(){
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        SqlSession sqlSession =(SqlSession) context.getBean("sqlSession");
        AttendanceMapper attendanceMapper=sqlSession.getMapper(AttendanceMapper.class);
        List<attendance> attendanceList=attendanceMapper.selectList(null);
        for (bean.attendance attendance : attendanceList) {
            System.out.println("id: " + attendance.getId()
                    + "    姓名： " + attendance.getName()
                    + "    状态： " + attendance.getStatus()
                    + "    时间： " + attendance.getTime()
            );
        }
    }

}
